﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _36_IsValidSudoku
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        public bool IsValidSudoku(char[,] board)
        {
            for (int i = 0; i < 9; i++)
            {
                HashSet<char> rows = new HashSet<char>();
                HashSet<char> columns = new HashSet<char>();
                HashSet<char> cube = new HashSet<char>();
                for (int j = 0; j < 9; j++)
                {
                    if (board[i,j] != '.' && !rows.Add(board[i,j]))
                        return false;
                    if (board[j,i] != '.' && !columns.Add(board[j,i]))
                        return false;
                    int RowIndex = 3 * (i / 3);
                    int ColIndex = 3 * (i % 3);
                    if (board[RowIndex + j / 3,ColIndex + j % 3] != '.' && !cube.Add(board[RowIndex + j / 3,ColIndex + j % 3]))
                        return false;
                }
            }
            return true;

        }
    }
}
